
Imports System
Imports System.Collections
Imports System.Data.SqlClient
Imports _2bMatesSite.Common


Namespace _2bMatesSite.BO
	''' <summary>
	''' Represents a static list of the user's direct friends.
	''' </summary>
	Public Class UsersFriends
		Inherits UserUsersList
		Public Sub New(ByVal usr As User)
			MyBase.New(usr)
		End Sub

		Public Sub New(ByVal userID As Integer)
			MyBase.New(userID)
		End Sub

		Protected Overloads Overrides Function LoadList(ByVal userID As Integer) As Hashtable
			Dim friendList As New Hashtable()

			Dim conn As SqlConnection = DBManager.GetUnmanagedConnection()
			Try
				Dim cmd As SqlCommand = GetCommand(conn)
				Dim dr As SqlDataReader = cmd.ExecuteReader()
				While dr.Read()
					Dim [friend] As New DirectFriend(userID, dr)
					friendList.Add([friend].GetHashCode(), [friend])
				End While
				dr.Close()
			Finally
				conn.Close()
			End Try

			Return friendList
		End Function

		Protected Overloads Overrides Sub ClearList()
			Throw New Exception("Can not use the user list object to manage friendship/invitations. Use the User object instead.")
		End Sub

		Protected Overloads Overrides Sub DeleteItem(ByVal fUID As Integer)
			Throw New Exception("Can not use the user list object to manage friendship/invitations. Use the User object instead.")
		End Sub

		Protected Overloads Overrides Sub DeleteItem(ByVal item As Object)
			Throw New Exception("Can not use the user list object to manage friendship/invitations. Use the User object instead.")
		End Sub

		Protected Overloads Overrides Function AddItem(ByVal item As Object) As Boolean
			Throw New Exception("Can not use the user list object to manage friendship/invitations. Use the User object instead.")
		End Function

		Protected Overridable Function GetCommand(ByVal conn As SqlConnection) As SqlCommand
			Dim cmd As New SqlCommand("SELECT * FROM DirectFriends WHERE (UID=@UID OR FriendUID=@UID) AND Status=1")
			cmd.Connection = conn
			cmd.Parameters.Add("@UID", userID)
			Return cmd
		End Function
	End Class
End Namespace






